package org.apache.util;

import java.util.Map;

import org.springframework.util.StringUtils;

public class StringUtil {

    public static String prepareCookies(Map<String, String> cookies, Map<String, String> currentCookies) {

        String strCookies = "";
        // first time
        if (currentCookies == null) {
            if (cookies != null) {
                for (Map.Entry<String, String> entry : cookies.entrySet()) {
                    strCookies += ";" + entry.getKey() + "=" + entry.getValue();
                }
            }
        } else {
            // append cookies
            if (cookies != null) {
                for (Map.Entry<String, String> entry : cookies.entrySet()) {
                    currentCookies.put(entry.getKey(), entry.getValue());
                }
                for (Map.Entry<String, String> entry : currentCookies.entrySet()) {
                    strCookies += ";" + entry.getKey() + "=" + entry.getValue();
                }
            }
        }
        return strCookies.length() > 0 ? strCookies.substring(1) : "";
    }

    public static Float getBalanceFromString(String totalBalanceStr) {

        Float amount = 0F;
        if (!StringUtils.isEmpty(totalBalanceStr)) {
            totalBalanceStr = totalBalanceStr.substring(0, totalBalanceStr.length() - 4);
            amount = Float.parseFloat(totalBalanceStr);
        }
        return amount;
    }

    public static String getName(String text) {

        String[] _name = text.split(" ");
        String name = "";
        for (int j = 0; j < _name.length - 1; j++) {
            name += " " + _name[j];
        }
        return name.substring(1);
    }

    public static String getContractType(String contractStr) {

        if (!StringUtils.isEmpty(contractStr)) {
            String[] contractType = contractStr.split(" ");
            String typeName = "";
            for (int i = 1; i < contractType.length; i++) {
                typeName += " " + contractType[i];
            }
            return typeName.substring(1);
        }
        return null;
    }

    public static void main(String a[]) {

        int ab = (int) Math.round(Float.parseFloat("7.5"));
        System.out.println(ab);
    }
}
